<template>
  <f7-page @page:reinit="getDataItems">
    <!--<f7-page @pageReinit="getDataItems">-->
    <f7-navbar title="会议申请列表" back-link="">
      <f7-nav-right  >
        <f7-link icon-f7="add" href="/oa/workflow/applyMeetingTable/-1"></f7-link>
      </f7-nav-right>
    </f7-navbar>

    <f7-list media-list>
      <f7-list-item
        swipeout
        v-for="(item) in items"
        v-bind:key="item.id"
        v-bind:title="item.orgName"
        v-bind:after="item.auditResult"
        v-bind:subtitle="item.projectName"
        v-bind:text="item.beginDate  + ' 到  '  +  item.endDate"
        @swipeout:open="saveCurItem(item)"
        @swipeout:deleted="delRecord">
        <f7-swipeout-actions right>
          <f7-swipeout-button close @click=" $refs.actionsOneGroup.open()">More</f7-swipeout-button>
        </f7-swipeout-actions>
      </f7-list-item>
    </f7-list>

    <f7-actions ref="actionsOneGroup">
      <f7-actions-group>
        <f7-actions-button @click="checkDetail">查看</f7-actions-button>
        <f7-actions-button v-show="isShow('编辑')" @click="editDetail">编辑</f7-actions-button>
        <f7-actions-button v-show="isShow('删除')" @click="delRecord">删除</f7-actions-button>
        <f7-actions-button v-show="isShow('启动')" @click="startApproval">启动</f7-actions-button>
        <f7-actions-button v-show="isShow('附件')" @click="uploadAddition">附件</f7-actions-button>
      </f7-actions-group>
      <f7-actions-group>
        <f7-actions-button color="red">Cancel</f7-actions-button>
      </f7-actions-group>
    </f7-actions>

  </f7-page>
</template>

<script>
    export default {
      name: "applyMeeting",
      data() {
        return {
          items: [],
          curItem: null
        }
      },
      mounted() {
        this.$f7ready((f7) => {
          let that = this;
          f7.request.setup({
            headers: {
              'AccessToken': sessionStorage.getItem('accessToken'),
              'JSESSIONID': sessionStorage.getItem('userToken')
            }
          });
          f7.request.json(that.GLOBAL.RequestAddress + '/camel/rest/meetingapplys', {
            'page': 1,
            'limit': 10,
            'jsonStr': '',
            'otherStr': '',
            'start': '0'
          }, function (result) {
            if (result.totalCount > 0) {
              that.items = result.data;
            }
          })
        })
      },
      watch: {
        items: {
          handler() {
          },
          deep: true
        }
      },
      methods: {
        getDataItems: function () {
          let that = this;
          let app = that.$f7;
          app.request.json(that.GLOBAL.RequestAddress + '/camel/rest/meetingapplys', {
            'page': 1,
            'limit': 10,
            'jsonStr': '',
            'otherStr': '',
            'start': '0'
          }, function (result) {
            if (result.totalCount >=0 ) {
              that.items = result.data;
            }
          });
        },
        isShow: function (label) {
          let status = -1;
          let that = this;
          if (that.curItem == null) {
            return false;
          }
          status = that.curItem.status;
          switch (status) {
            case 0 :
              if (label.includes("编辑")) {
                return true;
              } else if (label.includes("启动")) {
                return true;
              } else if (label.includes("删除")) {
                return true;
              } else if (label.includes("附件")) {
                return true;
              }
              break;
            case 1:
              if (label.includes("编辑")) {
                return false;
              } else if (label.includes("启动")) {
                return false;
              } else if (label.includes("删除")) {
                return false;
              } else if (label.includes("附件")) {
                return false;
              }
              break;
            case 2:
              if (label.includes("编辑")) {
                return false;
              } else if (label.includes("启动")) {
                return false;
              } else if (label.includes("删除")) {
                return false;
              } else if (label.includes("附件")) {
                return false;
              }
              break;
          }
        },
        saveCurItem: function (item) {
          this.curItem = item;
        },
        checkDetail: function () {
          this.$f7router.navigate("/oa/applyMeetingView/" + this.curItem.id)
        },
        editDetail: function () {
          this.$f7router.navigate("/oa/workflow/applyMeetingTable/" + this.curItem.id)
        },
        uploadAddition: function(){
          // this.$f7router.navigate("/oa/workflow/additionList/" + this.curItem.id)
          WebViewJavascriptBridge.startAttachManager(this.curItem.id);
        },
        delRecord: function () {
          let that = this;
          let url = that.GLOBAL.RequestAddress + "/camel/rest/Meetingpplys/" + that.curItem.id ;
          console.log(url)
          fetch(url,
            {
              method: "delete",
              headers: {
                "Content-Type": "application/json;charset=UTF-8",
                'AccessToken': sessionStorage.getItem('accessToken'),
                'JSESSIONID': sessionStorage.getItem('userToken')
              },
            }).then (response => response.json())
            .then(  result => {
              if (result.success == true) {
                let app = that.$f7;
                that.getDataItems();
              }
              that.showAlert("提示", result.msg)
            }).catch(function (err) {
            console.log("Fetch错误", err)
          });
          that.getDataItems();
        },
        startApproval: function () {
          let that = this;
          let url = that.GLOBAL.RequestAddress + "/camel/rest/meetingapplys/workflow/startProcess";
          let app = that.$f7;
          app.dialog.confirm("流程启动后业务数据将无法修改！确定要启动吗?", "提示", () => {
            app.request.json(url, {'id': that.curItem.id,}, function (result) {
              if (result.success == true) {
                that.getDataItems();
              }
              that.showAlert("提示", result["msg"])
            })
          })
        },
        showAlert: function (title, text) {
          let that = this;
          let app = that.$f7;
          app.dialog.alert(text, title, () => {
            //that.$f7router.back();
          });
        },
      }
    }
</script>

<style scoped>

</style>
